package com.yaozheng.vocationaltraining.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.bean.PKGameCategoryBean;
import com.yaozheng.vocationaltraining.bean.PKPlayerStatusBean;
import com.yaozheng.vocationaltraining.utils.BitmapLoader;
import com.yaozheng.vocationaltraining.widget.CircleImageView;

import java.util.List;

/**
 * Created by moon on 2017/11/16.
 */

public class PKPlayerStatusAdapter extends BaseAdapter {
    private LayoutInflater mInflater;//
    private Activity mContext;
    private BitmapLoader userBitmapLoader;

    private List<PKPlayerStatusBean> data = null;

    private int selectedPosition = -1;

    public PKPlayerStatusAdapter(Activity context,
                                 List<PKPlayerStatusBean> data) {
        this.mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.data = data;
        userBitmapLoader = new BitmapLoader(Glide.with(context), R.drawable.user_img);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(
                    R.layout.pk_player_status_list_item, null);
            holder = new ViewHolder();

            holder.userAvatarImage = (CircleImageView) convertView
                    .findViewById(R.id.userAvatarImage);
            holder.desc_textview = (TextView) convertView
                    .findViewById(R.id.desc_textview);
            holder.status_imageview = (ImageView) convertView
                    .findViewById(R.id.status_imageview);


            convertView.setTag(holder);//
        } else {
            holder = (ViewHolder) convertView.getTag();//
        }

        //加载图片
        userBitmapLoader.displayImage(data.get(position).getPlayerAvatar(), holder.userAvatarImage);
        if (data.get(position).getPlayerStatus() == 0){//0未准备 ， 1已准备 ，2 考试中
            holder.desc_textview.setText(data.get(position).getPlayerName()+"还未准备好！");
            holder.desc_textview.setTextColor(mContext.getResources().getColor(R.color.base_dialog_border_color));
            holder.status_imageview.setImageResource(R.drawable.not_ready_icon);
        }else if (data.get(position).getPlayerStatus() == 1){
            holder.desc_textview.setText(data.get(position).getPlayerName()+"已经准备就绪！");
            holder.desc_textview.setTextColor(mContext.getResources().getColor(R.color.black));
            holder.status_imageview.setImageResource(R.drawable.ready_icon);
        }
//        holder.name_textview.setText(data.get(position).getName());
//        holder.person_number_textview.setText(data.get(position).getAttended()+"");

        return convertView;
    }

    public void setData(List<PKPlayerStatusBean> data) {
        this.data = data;
    }

    public void setselectedPosition(int selectedPosition) {
        notifyDataSetChanged();;
    }

    class ViewHolder {
        CircleImageView userAvatarImage;
        TextView desc_textview;
        ImageView status_imageview;
    }
}
